import numpy as np

def get_arr2(raw,N):
    sum_ = np.array(raw).reshape(N,-1)
    return sum_

def add_(raw1,N1,raw2,N2):
    ans = []
    tst = []
    ans2 = []
    uuu1 = []
    uuu2 = []
    for i in range(0,N1):
        for j in range(0,N2):
            if raw1[i,1]==raw2[j,1]:
                ans.append([raw1[i,0]+raw2[j,0],raw1[i,1]])
                tst.append(raw1[i,1])

    for k in range(0, len(raw1)):
        for m in range(len(tst)):
            if raw1[k,1]== (tst[m] ):
                uuu1.append(k)

    raw1 = np.delete(raw1,uuu1,axis=0)

    for k in range(0, len(raw2)):
        for m in range(len(tst)):
            if raw2[k,1]== (tst[m] ):
                uuu2.append(k)

    raw2 = np.delete(raw2, uuu2, axis=0)
    ans2 = np.concatenate((raw1,raw2,ans),axis=0)
    ans2 = ans2[np.lexsort(-ans2.T[1,None])]

    return ans2


def output_converter(seq):
    tag = 0
    for i in range(len(seq)):
        if seq[i,0]!=0:
            print(seq[i,0],end=' ')
            if i == len(seq)-1:
                print(seq[i, 1], end='')
            else:
                print(seq[i, 1], end=' ')
        else:
            tag =1
    if tag!=0:
        print(0,end=' ')
        print(0, end='')
    print()
    return

def multiple_(raw1,N1,raw2,N2):
    ans = []
    tst = []
    uuu = []
    for i in range(0,N1):
        for j in range(0,N2):
            ans.append([raw1[i,0]*raw2[j,0],raw1[i,1]+raw2[j,1]])
    ans = np.array(ans)

    for i in range(len(ans)):
        for j in range(i+1,len(ans)):
            if (ans[i,1]==ans[j,1]):
                tst.append([ans[i,0]+ans[j,0],ans[i,1]])
    tst = np.array(tst)
    for i in  range(len(tst)):
        for j in range(len(ans)):
            if tst[i,1]==ans[j,1]:
                uuu.append(j)
    ans = np.delete(ans, uuu, axis=0)
    ans = np.concatenate((tst, ans), axis=0)
    ans = ans[np.lexsort(-ans.T[1, None])]
    return ans



def read_seq():
    raw = [int(n) for n in input().split()]
    N = raw[0]
    raw.remove(raw[0])
    return N,raw

if __name__ == '__main__':
    N1, raw1 = read_seq()
    N2, raw2 = read_seq()
    # N1 = 4
    # N2 = 3
    # raw1 = [3, 4, -5, 2, 6, 1, -2, 0]
    # raw2 = [5, 20, -7, 4, 3, 1]
    raw1_arr2 = get_arr2(raw1,N1)
    raw2_arr2 = get_arr2(raw2,N2)
    ans_muti = multiple_(raw1_arr2,N1,raw2_arr2,N2)
    output_converter(ans_muti)
    ans_add = add_(raw1_arr2,N1,raw2_arr2,N2)
    output_converter(ans_add)